<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>我的服务商</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/yzl.css"/>

</head>
<body>
<div id="blank" class="header" style="border-bottom:1px solid #D6D6D6;color:#000">
    <div v-back.tapmode class="back"></div>
    <span class="title">我的服务商</span>
    <span style="position:absolute;font-size:15px;right:10px" onclick="addshop()">添加</span>
</div>
<div v-cloak id="app" class="shop-container">
  <div class="shop-list" v-for="(member,index) in members">
    <div class="shop-container-area">
      <div class="shop-card" :style="getBg(member)">
        <span class="shop-deadline">有效期至：<span style="color:#BF0808">{{member.duration_type == 1 && member.date_level_end ? member.date_level_end : '永久'| date2}}</span></span>
      </div>
      <div class="shop-content" style="float:right">
        <div class="shop-title">{{member.nickname}}</div>
        <div class="shop-level">[{{member.name}}]</div>
        <div v-myclick="[member.member_id, changeMember]" class="shop-status" v-bind:class="{'muactive':index!==0}">{{index == 0 ? '当前服务商' : '切换服务商'}}</div>
      </div>
    </div>
  </div>
</div>
</body>
<script src="../../script/api.js"></script>
<script src="../../script/vue.js"></script>
<script src="../../script/app.js"></script>
<script src="../../script/common.js"></script>
<script src="../../script/url.js"></script>
<script>

    var members;
    apiready = function () {
        if (!getPrefs('token')) {
            reLogin();
            return;
        }
        showProgress();
        setBSImg();
        new Vue({
            el: '#blank'
        });

        var data = {
            member_id: getPrefs('member_id')
        };
        var callback = function (ret) {
            members = ret.content;
            initApp();
            api.parseTapmode();
        };
        pinet.post(URL.getMembers, data, callback);
        addListeners();
    };

    function initApp() {
        new Vue({
            el: '#app',
            data: {
                members: members,
                imgPath: '../../image/',
            },
            methods: {
                changeMember: function (member_id) {
                    closeWin('user2');
                    closeWin('index');
                    showProgress();
                    var data = {
                        member_id: member_id
                    };
                    var callback = function (ret) {
                        var user = ret.content;
                        setPrefs('user', user);
                        setPrefs('member_id', user.member_id);
                        if(user.level_id == '7' || user.level_id == '8') {
                            openWin('user2', {fromshoplist:true});
                        }else{
                            onPageEnd();
                            openWin('../../index', {to:3,fromshoplist:true});
                        }
                    };
                    pinet.post(URL.getUserinfo, data, callback);

                },
                getBg: function (member) {
                    var memberStyle = getMemberStyle(member.level_id);
                    return {
                        backgroundImage: 'url(' + this.imgPath + Vue.BSImg + '/' + memberStyle.usercard_change + ')',
                    }
                }
            }
        })
    }

    function addListeners() {
        api.addEventListener({
            name: 'viewappear'
        }, function () {
            onPageStart();
        });

        api.addEventListener({
            name: 'viewdisappear'
        }, function () {
            onPageEnd();
        });

        api.addEventListener({
            name: 'keyback'
        }, function () {
            onPageEnd();
            api.closeWin();
        });

        api.addEventListener({
            name: 'shoplist'
        }, function () {
            window.location.reload();
        });
    }

    function addshop(){
      if (!getPrefs('token')) {
          reLogin();
          return;
      }
      openWin('addshop')
    }

</script>
</html>
